import {Component, OnInit} from '@angular/core';
import {TreeModel, NodeEvent, RenamableNode, Ng2TreeSettings} from 'ng2-tree';

declare const alertify: any;

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  constructor() {
  }

  ngOnInit() {
  }

  public fonts: TreeModel = {
    value: '一级菜单',
    children: [
      {
        value: '二级菜单1',
        settings: {
          'static': true
        },
        children: [
          {value: '三级菜单1'},
          {value: '三级菜单2'},
          {value: '三级菜单3'},
          {value: '三级菜单4'},
          {value: '三级菜单5'},
          {
            value: '三级菜单6',
            children: [
              {value: '四级菜单1'},
              {value: '四级菜单2'},
              {value: '四级菜单3'}
            ]
          }
        ]
      },
      {
        value: '二级菜单2',
        children: [
          {value: '三级菜单1'},
          {value: '三级菜单2'},
          {value: '三级菜单3'},
          {value: '三级菜单4'},
          {value: '三级菜单5'},
          {value: '三级菜单6'}
        ]
      },
      {
        value: '二级菜单3',
        // children property is ignored if "loadChildren" is present
        children: [{value: 'I am the font that will be ignored'}],
        loadChildren: (callback) => {
          setTimeout(() => {
            callback([
              {value: '三级菜单1'},
              {value: '三级菜单2'},
              {value: '三级菜单3'},
              {value: '三级菜单4'},
            ]);
          }, 5000);
        }
      }
    ]
  };


  private static logEvent(e: NodeEvent, message: string): void {
    console.log(e);
    // alertify.message(`${message}: ${e.node.value}`);
  }

  public onNodeRemoved(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Removed');
  }

  public onNodeMoved(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Moved');
  }

  public onNodeRenamed(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Renamed');
  }

  public onNodeCreated(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Created');
  }

  public onNodeSelected(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Selected');
  }

  public onNodeExpanded(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Expanded');
  }

  public onNodeCollapsed(e: NodeEvent): void {
    HomeComponent.logEvent(e, 'Collapsed');
  }

  hh;

  onClick() {
    console.log(this.fonts);
    console.log("这是一级菜单:"+this.fonts.value);
    console.log("这是二级菜单:"+this.fonts.children);
    console.log("这是二级菜单的一级目录:"+this.fonts.children[0].value);
    console.log("这是三级菜单一级目录:"+this.fonts.children[0].children[0].value);
  }
}
